package com.tjc.spring.core.resource;

/**
 * @Author: tjc
 * @description
 * @Date Created in 22:20 2021-12-21
 */
public class ResourceLoader {

    public static Resource getResource(String configLocation) {
        String[] arr = configLocation.split(":", 2);
        if (arr == null || arr.length < 2) {
            throw new RuntimeException("resource path is exception.");
        }
        String resourceType = arr[0];
        String path = arr[1];
        if ("classpath".equals(resourceType)) {
            return new ClassPathResource(path);
        } else if ("file".equals(resourceType)) {
            return new FileSystemResource(path);
        } else {
            throw new RuntimeException("unsopport resource type!");
        }
    }
}
